﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;
using SignalrServer.Hubs;
// using Microsoft.AspNetCore.Sockets;

namespace SignalrServer.Controllers
{
    [Route("api/[controller]")]
    public class ValuesController : Controller
    {
        ///Users/lousaibiao/TestProjects/signalr-demo/SignalrServer/SignalrServer.csproj
        private readonly IHubContext<Chat> chatHub;
        public ValuesController(IHubContext<Chat> chatHub)
        {
            this.chatHub = chatHub;
        }
        // private readonly hubcontext
        // GET api/values
        [HttpGet, Route("sendmsg")]
        public async Task<IActionResult> Get(Person p)
        {
            await chatHub.Clients.All.InvokeAsync("Test", JsonConvert.SerializeObject(p));
            return Ok("asdf");
        }
        /// <summary>
        /// Test
        /// </summary>
        /// <returns></returns>

        [HttpGet, Route("Test")]
        public async Task<IActionResult> Test()
        {
            return Ok(new { success = true,msg = DateTime.Now.ToString("") });
        }
    }

    public class Person
    {
        public int Id { get; set; }
        public string msg { get; set; }
    }
}
